package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NuseringProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NuseringProjectServiceImpl implements NuseringProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * @Description: 通过id查询护理项目
     * @Param: [java.lang.Long]
     * @return: com.zzyl.entity.NursingProject
     * @author:fsq
     * @date: 2024/5/28 11:50
     */
    @Override
    public NursingProjectVo getById(Long id) {
        /*entity是用来接收从数据库查询出来的数据*/
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        NursingProjectVo nursingProjectVo = new NursingProjectVo();
        BeanUtil.copyProperties(nursingProject, nursingProjectVo);
        return nursingProjectVo;
    }

    /**
     * @Description: 查询所有护理项目
     * @Param: []
     * @return: java.util.List<com.zzyl.entity.NursingProject>
     * @author:fsq
     * @date: 2024/5/28 11:51
     */
    @Override
    public List<NursingProject> getAll() {
        return null;
    }

    /**
     * @Description: 增加护理项目
     * @Param: [com.zzyl.entity.NursingProject]
     * @return: void
     * @author:fsq
     * @date: 2024/5/28 11:51
     */
    @Override
    public void addNursingProject(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtil.copyProperties(nursingProjectDto, nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }

    /**
     * @Description: 修改护理项目
     * @Param: [com.zzyl.entity.NursingProject]
     * @return: void
     * @author:fsq
     * @date: 2024/5/28 11:51
     */
    @Override
    public void updateNursingProject(NursingProjectDto nursingProjectDto) {
        /*换成entity,放进数据库*/
        NursingProject nursingProject = new NursingProject();
        BeanUtil.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * @Description: 删除护理项目
     * @Param: [java.lang.Long]
     * @return: void
     * @author:fsq
     * @date: 2024/5/28 11:52
     */
    @Override
    public void deleteNursingProject(Long id) {
        nursingProjectMapper.delete(id);
    }

    /**
     * @Description: 条件分页查询护理项目
     * @Param: [java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Integer]
     * @return: com.zzyl.base.PageResponse<com.zzyl.vo.NursingProjectVo>
     * @author:fsq
     * @date: 2024/5/28 12:03
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProjectVo> byPage = nursingProjectMapper.getByPage(name, status);
        return PageResponse.of(byPage, NursingProjectVo.class);
    }

    /**
    * @Description: 根据护理项目更改状态启用禁用
    * @Param: [java.lang.Integer, java.lang.Integer]
    * @return: void
    * @author:fsq
    * @date: 2024/5/30 20:04
    */
    @Override
    public void updateStatusById(long id, int status) {
        //首先根据id查询护理项目
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        nursingProject.setStatus(status);
        nursingProjectMapper.update(nursingProject);
    }
}
